import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:ls_work/res/colors.dart';
import 'package:ls_work/viewmodel/event_manage/add_event_handle_view_model.dart';
import 'package:ls_work/widgets/add_image_widget.dart';

import '../../util/utils.dart';
import '../../viewmodel/event_manage/event_manage_list_viewmodel.dart';

class AddEventHandlePage extends BaseStatefulMvvmWidget{
  final dynamic eventId;

  AddEventHandlePage({@required this.eventId});

  @override
  State<StatefulWidget> createState() => _AddEventHandleState();

}

class _AddEventHandleState extends BaseMvvmState<AddEventHandleViewModel,AddEventHandlePage>{
  @override
  Widget buildLoadingContentView() {
    return Column(
      children: [
        SizedBox(height: 20,),
        CommonInput(
          isDense: true,
          padding: EdgeInsets.zero,
          border: InputBorder.none,
          hintText: '请输入事件跟踪记录',
          minLines: 7,
          maxLines: 7,
          onChanged: (str){
            viewModel.detail = str;
          },
          keyboardType: CommonInputType.multiline,
        ).addToContainer(
          decoration: BoxDecoration(
            color: Colours.bg_color,
            borderRadius: 10.borderRadius
          ),
          margin: EdgeInsets.symmetric(horizontal: 16),
          padding: EdgeInsets.symmetric(horizontal: 10,vertical: 10)
        ),

        SizedBox(height: 16,),
        AddAndUploadImageWidget((files, modelList) {
          setState(() {
            viewModel.files = files;
          });
        },files: viewModel.files,
          cameramsg: "拍摄事件跟进照片，需要申请您的相机权限",
          photomsg: "从相册选取事件跟进照片，需要申请您的相册权限",
        ),
        SizedBox(height: 16,),
        TextButton(onPressed: (){
          viewModel.createHandle();
        }, child: CommonText('提交',textColor: Colors.white),
        style: ButtonStyle(
          backgroundColor: WidgetStateProperty.all(Colors.blue),
          shape: WidgetStateProperty.all(StadiumBorder()),
          minimumSize: WidgetStateProperty.all(Size(MediaQuery.of(context).size.width-32,49))
        ),)
      ],
    );
  }

  @override
  Widget buildRootView(BuildContext context, Widget loadingContentWidget) {
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBar(
        title: Text('事件处理'),
        actions: [
          IconButton(onPressed: (){
            Utils.launchTelURL(sosPhone);
          }, icon: Icon(Icons.call))
        ],
      ),
      body: loadingContentWidget,
    );
  }

  @override
  AddEventHandleViewModel createViewModel() {
    return AddEventHandleViewModel(context,eventId: widget.eventId);
  }

  @override
  void onRetryClick() {
  }

}